/**
 * @author xy xinyu@staff.sina.com.cn
 */
function trace(msg) {
}
var htmlbody, a;
if (typeof preader == 'undefined')
	var preader = {};

preader.ua = navigator.userAgent.toLowerCase();
preader.ie = /msie/.test(preader.ua);
preader.firefox = /firefox/.test(preader.ua);

function postIframe(href, title) {// 用来提交的iframe
	trace(' in  postIframe ');
	var d = document, l = d.location, e = window.getSelection, k = d.getSelection, x = d.selection, s = String(e
			? e()
			: (k) ? k() : (x ? x.createRange().text : '')), e = encodeURIComponent, z = d
			.createElement('scr' + 'ipt'), p = 'i=' + identity + '&u='
			+ e(href) + '&t=' + e(title) + '&s=' + e(s.length < 10240 ? s : '');

	var b = htmlbody.replace(/<!--.*?-->/ig, '');

	if (preader.ie || b.length > 65534) {// ie has domain forbiden ,so ...
		window.location.href = (document.location.protocol
				+ "//www.xiabandu.com/article/hello.php?cookie-notice=1&identity="
				+ identity + "&u=" + e(window.location) + '&t='
				+ e(document.title) + '&s=' + e(s));
	} else {
		// document.body.innerHTML = b;
		i = document.createElement('iframe');
		i.setAttribute('name', 'preaderiframe');
		i.setAttribute('id', 'preaderiframe');

		i
				.setAttribute(
						'style',
						'left:10px;top:10px;width:168px;z-index: 50000; position: fixed; width:180px;height:100px; border: 3px solid #aaa;');
		document.body.appendChild(i);
		i.onload = function() {
			setTimeout(closeIframe, 5000);
		}

		window['preaderiframe'].document
				.write('<html><body style="color: #555; background-color: #fff; text-align: center; margin: 0px; font-family: Georgia, Times, serif; font-size: 26px;">'
						+ '<div style="text-align: center; width: 80%; padding-bottom: 1px; margin: 0 auto 15px auto; font-size: 13px; border-bottom: 1px solid #ccc; color: #333;">reader</div>'
						+ 'Saving...'
						+ '<form action="'
						+ document.location.protocol // http:
						+ '//www.xiabandu.com/api/receive.php" method="post" id="f" accept-charset="utf-8">'
						+ '<input type="hidden" name="pars" id="pars" value="'
						+ p // a=&k=o35xfsVTJGR4&u=http://blog.sina.com.cn/wxy830827&t=xinyu_新浪博客&s=
						+ '"/>'
						+ '<input type="hidden" name="b" id="b" value=""/>'
						+ '</form>'
						+ '<scr'
						+ 'ipt>setTimeout(function() {document.getElementById("b").value = decodeURIComponent("'
						+ e(b)
						+ '"); document.getElementById("f").submit(); }, 1);</scr'
						+ 'ipt>' + '</body></html>');
	}

}

function closeIframe() {
	var f = document.getElementById('preaderiframe');
	f.style.display = 'none';
	f.parentNode.removeChild(f);
}

function showNode() {
	var b = htmlbody.replace(/<!--.*?-->/ig, '');
	// alert(b);
}
function start() {

	try {
		function readabilityCompleted(bodyNode) {
			htmlbody = bodyNode.innerHTML;
			trace('in ipReadabilityCompleted');
			// showNode();
			postIframe(document.location.href, document.title);
		}

		var dbg = function(s) {
			if (typeof console !== 'undefined')
				console.log("Readability: " + s);
		};

		var readability = {
			version : '0.5.1',
			iframeLoads : 0,
			documentNode : null,
			bodyNode : null,
			ie : false,
			firefox : false,
			safari : false,
			chrome : false,

			regexps : {
				unlikelyCandidatesRe : /combx|comment|disqus|foot|header|menu|meta|nav|rss|shoutbox|sidebar|sponsor/i,
				okMaybeItsACandidateRe : /and|article|body|column|main/i,
				positiveRe : /article|body|content|entry|hentry|page|pagination|post|text/i,
				negativeRe : /combx|comment|contact|foot|footer|footnote|link|media|meta|promo|related|scroll|shoutbox|sponsor|tags|widget/i,
				divToPElementsRe : /<(a|blockquote|dl|div|img|ol|p|pre|table|ul)/i,
				replaceBrsRe : /(<br[^>]*>[ \n\r\t]*){2,}/gi,
				replaceFontsRe : /<(\/?)font[^>]*>/gi,
				trimRe : /^\s+|\s+$/g,
				normalizeRe : /\s{2,}/g,
				killBreaksRe : /(<br\s*\/?>(\s|&nbsp;?)*){1,}/g,
				videoRe : /http:\/\/(www\.)?(youtube|vimeo)\.com/i
			},

			init : function(a, b) {
				var _ua = navigator.userAgent.toLowerCase();

				readability.ie = /msie/.test(_ua);
				readability.safari = /safari/.test(_ua);
				readability.firefox = /firefox/.test(_ua);
				readability.chrome = /chrome/.test(_ua);

				readability.documentNode = a;// 相当于document
				readability.bodyNode = b;

				// 清楚script和style
				readability.removeScript(readability.bodyNode);
				readability.removeStyle(readability.bodyNode);

				// readability.removeScript(document);
				// readability.removeStyle(document);

				readability.prepDocument();

				/* Build readability's DOM tree */
				var overlay = document.createElement("DIV");
				var innerDiv = document.createElement("DIV");
				overlay.id = "readOverlay";
				innerDiv.id = "readInner";

				/* Apply user-selected styling */
				readability.bodyNode.className = readStyle;
				overlay.className = readStyle;
				innerDiv.className = readMargin + " " + readSize;
				// 过滤标题出来
				var articleTitle = readability.getArticleTitle();
				innerDiv.appendChild(articleTitle);
				// 过滤内容出来
				var articleContent = readability.grabArticle();
				innerDiv.appendChild(articleContent);

				overlay.appendChild(innerDiv);
				readability.bodyNode.innerHTML = "";
				readability.bodyNode.insertBefore(overlay,
						readability.bodyNode.firstChild);

				htmlbody = readability.bodyNode.innerHTML;
				// document.body.innerHTML=htmlbody;

			},

			addStyle : function() {
				// var x='<link rel="stylesheet"
				// href="http://pages.sinaapp.com/read/css/readability.css"
				// type="text/css" media="screen">';
				var l = document.createElement('link');
				l.href = 'http://www.xiabandu.com/css/read.css';
				l.setAttribute('ref', 'stylesheet');
				l.ref = "stylesheet";
				document.getElementsByTagName('head')[0].appendChild(l);
			},
			/**
			 * Get the article title as an H1. Currently just uses
			 * document.title, we might want to be smarter in the future.
			 * 
			 * @return void
			 */
			getArticleTitle : function() {
				if (readability.ie) {
					var articleTitle = document.createElement("H1");
					articleTitle.innerHTML = document.title;
				} else {
					var articleTitle = document.createElement("H1");
					articleTitle.innerHTML = document.title.replace(
							readability.regexps.trimRe, "")
				}

				return articleTitle;
			},

			removeScript : function(a) {
				a = a.getElementsByTagName("script");
				for (var b = a.length - 1; b >= 0; b -= 1)
					if (typeof a[b].src === "undefined"
							|| a[b].src.indexOf("readability") === -1
							&& a[b].src.indexOf("typekit") === -1) {
						a[b].nodeValue = "";
						a[b].removeAttribute("src");
						a[b].parentNode && a[b].parentNode.removeChild(a[b])
					}
			},

			removeStyle : function(a) {
				// normal model, direct return;
				return;
				if (readability.ie) {
					for (var k = 0; k < document.styleSheets.length; k++) {
						if (k == document.styleSheets.length - 1) {
							document.styleSheets[k].href = "http://www.xiabandu.com/css/read.css";
							continue;
						}
						if (document.styleSheets[k].href != null
								&& document.styleSheets[k].href
										.lastIndexOf("readability") == -1) {
							document.styleSheets[k].disabled = true;
						}
					}
				} else {
					b = a.getElementsByTagName("style");
					for (var i = b.length - 1; i >= 0; i--) {
						b[i].parentNode.removeChild(b[i]);
					}

					c = a.getElementsByTagName("link");
					for (var i = c.length - 1; i >= 0; i--) {
						if (c[i].rel == 'stylesheet')
							c[i].parentNode.removeChild(c[i]);
					}
					readability.addStyle();
				}
			},

			/**
			 * Prepare the HTML document for readability to scrape it. This
			 * includes things like stripping javascript, CSS, and handling
			 * terrible markup.
			 * 
			 * @return void
			 */
			prepDocument : function() {
				/**
				 * In some cases a body element can't be found (if the HTML is
				 * totally hosed for example) so we create a new body node and
				 * append it to the document.
				 */
				if (readability.bodyNode === null) {
					body = document.createElement("body");
					try {
						readability.bodyNode = body;
					} catch (e) {
						readability.bodyNode.appendChild(body);
					}
				}

				readability.bodyNode.innerHTML = readability.bodyNode.innerHTML
						.replace(readability.regexps.replaceBrsRe, '</p><p>')
						.replace(readability.regexps.replaceFontsRe, '<$1span>')
						.replace(/<!--.*?-->/ig, '');
			},

			/**
			 * Prepare the article node for display. Clean out any inline
			 * styles, iframes, forms, strip extraneous
			 * <p>
			 * tags, etc.
			 * 
			 * @param Element
			 * @return void
			 */
			prepArticle : function(articleContent) {
				readability.cleanStyles(articleContent);
				readability.killBreaks(articleContent);

				/* Clean out junk from the article content */
				readability.clean(articleContent, "form");
				readability.clean(articleContent, "object");
				readability.clean(articleContent, "h1");
				/***************************************************************
				 * If there is only one h2, they are probably using it as a
				 * header and not a subheader, so remove it since we already
				 * have a header.
				 **************************************************************/
				if (articleContent.getElementsByTagName('h2').length == 1)
					readability.clean(articleContent, "h2");
				readability.clean(articleContent, "iframe");

				readability.cleanHeaders(articleContent);

				/*
				 * Do these last as the previous stuff may have removed junk
				 * that will affect these
				 */
				readability.cleanConditionally(articleContent, "table");
				readability.cleanConditionally(articleContent, "ul");
				readability.cleanConditionally(articleContent, "div");

				/* Remove extra paragraphs */
				var articleParagraphs = articleContent
						.getElementsByTagName('p');
				for (i = articleParagraphs.length - 1; i >= 0; i--) {
					var imgCount = articleParagraphs[i]
							.getElementsByTagName('img').length;
					var embedCount = articleParagraphs[i]
							.getElementsByTagName('embed').length;
					var objectCount = articleParagraphs[i]
							.getElementsByTagName('object').length;

					if (imgCount == 0
							&& embedCount == 0
							&& objectCount == 0
							&& readability.getInnerText(articleParagraphs[i],
									false) == '') {
						articleParagraphs[i].parentNode
								.removeChild(articleParagraphs[i]);
					}
				}

				try {
					articleContent.innerHTML = articleContent.innerHTML
							.replace(/<br[^>]*>\s*<p/gi, '<p');
				} catch (e) {
					dbg("Cleaning innerHTML of breaks failed. This is an IE strict-block-elements bug. Ignoring.");
				}
			},

			/**
			 * Initialize a node with the readability object. Also checks the
			 * className/id for special names to add to its score.
			 * 
			 * @param Element
			 * @return void
			 */
			initializeNode : function(node) {
				node.readability = {
					"contentScore" : 0
				};
				switch (node.tagName) {
					case 'DIV' :
						node.readability.contentScore += 5;
						break;

					case 'PRE' :
					case 'TD' :
					case 'BLOCKQUOTE' :
						node.readability.contentScore += 3;
						break;

					case 'ADDRESS' :
					case 'OL' :
					case 'UL' :
					case 'DL' :
					case 'DD' :
					case 'DT' :
					case 'LI' :
					case 'FORM' :
						node.readability.contentScore -= 3;
						break;

					case 'H1' :
					case 'H2' :
					case 'H3' :
					case 'H4' :
					case 'H5' :
					case 'H6' :
					case 'TH' :
						node.readability.contentScore -= 5;
						break;
				}

				node.readability.contentScore += readability
						.getClassWeight(node);
			},

			/*******************************************************************
			 * grabArticle - Using a variety of metrics (content score,
			 * classname, element types), find the content that is most likely
			 * to be the stuff a user wants to read. Then return it wrapped up
			 * in a div.
			 * 
			 * @return Element
			 */
			grabArticle : function() {
				for (var nodeIndex = 0; (node = readability.bodyNode
						.getElementsByTagName('*')[nodeIndex]); nodeIndex++) {
					// tag 398 --------------------------------------------
					if (node.tagName === "DIV") {
						var _nodetext = "";
						if (readability.ie) {
							_nodetext = node.innerText;
						} else {
							_nodetext = node.innerHTML;
						}
						if (_nodetext
								.search(readability.regexps.divToPElementsRe) === -1) {
							dbg("Altering div to p");
							var newNode = document.createElement('p');
							try {
								if (readability.ie) {
									newNode.innerText = _nodetext;
								} else {
									newNode.innerHTML = _nodetext;
								}
								node.parentNode.replaceChild(newNode, node);
								nodeIndex--;
							} catch (e) {
								dbg("Could not alter div to p, probably an IE restriction, reverting back to div.")
							}
						} else {
							/* EXPERIMENTAL */
							for (var i = 0, il = node.childNodes.length; i < il; i++) {
								var childNode = node.childNodes[i];
								if (childNode.nodeType == Node.TEXT_NODE) {
									dbg("replacing text node with a p tag with the same content.");
									var p = document.createElement('p');
									p.innerHTML = childNode.nodeValue;
									p.style.display = 'inline';
									p.className = 'readability-styled';
									childNode.parentNode.replaceChild(p,
											childNode);
								}
							}
						}
					}// end of tag 398
				}
				/**
				 * Loop through all paragraphs, and assign a score to them based
				 * on how content-y they look. Then add their score to their
				 * parent node.
				 * 
				 * A score is determined by things like number of commas, class
				 * names, etc. Maybe eventually link density.
				 */
				var allParagraphs = readability.bodyNode
						.getElementsByTagName("p");
				var candidates = [];

				for (var j = 0; j < allParagraphs.length; j++) {
					var parentNode = allParagraphs[j].parentNode;
					// var grandParentNode = parentNode.parentNode;

					var innerText = readability.getInnerText(allParagraphs[j]);

					/*
					 * If this paragraph is less than 25 characters, don't even
					 * count it.
					 */
					if (innerText.length < 25)
						continue;

					/* Initialize readability data for the parent. */
					if (typeof parentNode.readability == 'undefined') {
						readability.initializeNode(parentNode);
						candidates.push(parentNode);
					}

					/*
					 * Initialize readability data for the grandparent. if
					 * (typeof grandParentNode.readability == 'undefined') {
					 * readability.initializeNode(grandParentNode);
					 * candidates.push(grandParentNode); }
					 */
					var contentScore = 0;

					/* Add a point for the paragraph itself as a base. */
					contentScore++;

					/* Add points for any commas within this paragraph */
					contentScore += innerText.split(',').length;

					/*
					 * For every 100 characters in this paragraph, add another
					 * point. Up to 3 points.
					 */
					contentScore += Math.min(
							Math.floor(innerText.length / 100), 3);

					/* Add the score to the parent. The grandparent gets half. */
					parentNode.readability.contentScore += contentScore;

					// grandParentNode.readability.contentScore += contentScore/
					// 2;
				}

				/**
				 * After we've calculated scores, loop through all of the
				 * possible candidate nodes we found and find the one with the
				 * highest score.
				 */
				var topCandidate = null;
				for (var i = 0, il = candidates.length; i < il; i++) {
					/**
					 * Scale the final candidates score based on link density.
					 * Good content should have a relatively small link density
					 * (5% or less) and be mostly unaffected by this operation.
					 */
					candidates[i].readability.contentScore = candidates[i].readability.contentScore
							* (1 - readability.getLinkDensity(candidates[i]));

					dbg('Candidate: ' + candidates[i] + " ("
							+ candidates[i].className + ":" + candidates[i].id
							+ ") with score "
							+ candidates[i].readability.contentScore);

					if (!topCandidate
							|| candidates[i].readability.contentScore > topCandidate.readability.contentScore)
						topCandidate = candidates[i];
				}

				/**
				 * If we still have no top candidate, just use the body as a
				 * last resort. We also have to copy the body node so it is
				 * something we can modify.
				 */
				if (topCandidate == null || topCandidate.tagName == "BODY") {
					topCandidate = document.createElement("DIV");
					topCandidate.innerHTML = readability.bodyNode.innerHTML;
					readability.bodyNode.innerHTML = "";
					readability.bodyNode.appendChild(topCandidate);
					readability.initializeNode(topCandidate);
				}

				/**
				 * Now that we have the top candidate, look through its siblings
				 * for content that might also be related. Things like
				 * preambles, content split by ads that we removed, etc.
				 */
				var articleContent = document.createElement("DIV");
				articleContent.id = "readability-content";
				var siblingScoreThreshold = Math.max(10,
						topCandidate.readability.contentScore * 0.2);
				var siblingNodes = topCandidate.parentNode.childNodes;
				for (var i = 0, il = siblingNodes.length; i < il; i++) {
					var siblingNode = siblingNodes[i];
					var append = false;

					dbg("Looking at sibling node: "
							+ siblingNode
							+ " ("
							+ siblingNode.className
							+ ":"
							+ siblingNode.id
							+ ")"
							+ ((typeof siblingNode.readability != 'undefined')
									? (" with score " + siblingNode.readability.contentScore)
									: ''));
					dbg("Sibling has score "
							+ (siblingNode.readability
									? siblingNode.readability.contentScore
									: 'Unknown'));

					if (siblingNode === topCandidate) {
						append = true;
					}

					if (typeof siblingNode.readability != 'undefined'
							&& siblingNode.readability.contentScore >= siblingScoreThreshold) {
						append = true;
					}

					if (siblingNode.nodeName == "P") {
						var linkDensity = readability
								.getLinkDensity(siblingNode);
						var nodeContent = readability.getInnerText(siblingNode);
						var nodeLength = nodeContent.length;

						if (nodeLength > 80 && linkDensity < 0.25) {
							append = true;
						} else if (nodeLength < 80 && linkDensity == 0
								&& nodeContent.search(/\.( |$)/) !== -1) {
							append = true;
						}
					}

					if (append) {
						dbg("Appending node: " + siblingNode)

						/*
						 * Append sibling and subtract from our list because it
						 * removes the node when you append to another node
						 */
						articleContent.appendChild(siblingNode);
						i--;
						il--;
					}
				}

				/**
				 * So we have all of the content that we need. Now we clean it
				 * up for presentation.
				 */
				readability.prepArticle(articleContent);

				return articleContent;
			},

			/**
			 * Get the inner text of a node - cross browser compatibly. This
			 * also strips out any excess whitespace to be found.
			 * 
			 * @param Element
			 * @return string
			 */
			getInnerText : function(e, normalizeSpaces) {
				var textContent = "";

				normalizeSpaces = (typeof normalizeSpaces == 'undefined')
						? true
						: normalizeSpaces;

				if (navigator.appName == "Microsoft Internet Explorer")
					textContent = e.innerText.replace(
							readability.regexps.trimRe, "");
				else
					textContent = e.textContent.replace(
							readability.regexps.trimRe, "");

				if (normalizeSpaces)
					return textContent.replace(readability.regexps.normalizeRe,
							" ");
				else
					return textContent;
			},

			/**
			 * Get the number of times a string s appears in the node e.
			 * 
			 * @param Element
			 * @param string -
			 *            what to split on. Default is ","
			 * @return number (integer)
			 */
			getCharCount : function(e, s) {
				s = s || ",";
				return readability.getInnerText(e).split(s).length;
			},

			/**
			 * Remove the style attribute on every e and under. TODO: Test if
			 * getElementsByTagName(*) is faster.
			 * 
			 * @param Element
			 * @return void
			 */
			cleanStyles : function(e) {
				e = e || document;
				var cur = e.firstChild;

				if (!e)
					return;

				// Remove any root styles, if we're able.
				if (typeof e.removeAttribute == 'function'
						&& e.className != 'readability-styled')
					e.removeAttribute('style');

				// Go until there are no more child nodes
				while (cur != null) {
					if (cur.nodeType == 1) {
						// Remove style attribute(s) :
						if (cur.className != "readability-styled") {
							cur.removeAttribute("style");
						}
						readability.cleanStyles(cur);
					}
					cur = cur.nextSibling;
				}
			},

			/**
			 * Get the density of links as a percentage of the content This is
			 * the amount of text that is inside a link divided by the total
			 * text in the node.
			 * 
			 * @param Element
			 * @return number (float)
			 */
			getLinkDensity : function(e) {
				var links = e.getElementsByTagName("a");
				var textLength = readability.getInnerText(e).length;
				var linkLength = 0;
				for (var i = 0, il = links.length; i < il; i++) {
					linkLength += readability.getInnerText(links[i]).length;
				}

				return linkLength / textLength;
			},

			/**
			 * Get an elements class/id weight. Uses regular expressions to tell
			 * if this element looks good or bad.
			 * 
			 * @param Element
			 * @return number (Integer)
			 */
			getClassWeight : function(e) {
				var weight = 0;

				/* Look for a special classname */
				if (e.className != "") {
					if (e.className.search(readability.regexps.negativeRe) !== -1)
						weight -= 25;

					if (e.className.search(readability.regexps.positiveRe) !== -1)
						weight += 25;
				}

				/* Look for a special ID */
				if (typeof(e.id) == 'string' && e.id != "") {
					if (e.id.search(readability.regexps.negativeRe) !== -1)
						weight -= 25;

					if (e.id.search(readability.regexps.positiveRe) !== -1)
						weight += 25;
				}

				return weight;
			},

			/**
			 * Remove extraneous break tags from a node.
			 * 
			 * @param Element
			 * @return void
			 */
			killBreaks : function(e) {
				try {
					e.innerHTML = e.innerHTML.replace(
							readability.regexps.killBreaksRe, '<br />');
				} catch (e) {
					dbg("KillBreaks failed - this is an IE bug. Ignoring.");
				}
			},

			/**
			 * Clean a node of all elements of type "tag". (Unless it's a
			 * youtube/vimeo video. People love movies.)
			 * 
			 * @param Element
			 * @param string
			 *            tag to clean
			 * @return void
			 */
			clean : function(e, tag) {
				var targetList = e.getElementsByTagName(tag);
				var isEmbed = (tag == 'object' || tag == 'embed');

				for (var y = targetList.length - 1; y >= 0; y--) {
					/*
					 * Allow youtube and vimeo videos through as people usually
					 * want to see those.
					 */
					if (isEmbed
							&& targetList[y].innerHTML
									.search(readability.regexps.videoRe) !== -1) {
						continue;
					}

					targetList[y].parentNode.removeChild(targetList[y]);
				}
			},

			/**
			 * Clean an element of all tags of type "tag" if they look fishy.
			 * "Fishy" is an algorithm based on content length, classnames, link
			 * density, number of images & embeds, etc.
			 * 
			 * @return void
			 */
			cleanConditionally : function(e, tag) {
				var tagsList = e.getElementsByTagName(tag);
				var curTagsLength = tagsList.length;

				/**
				 * Gather counts for other typical elements embedded within.
				 * Traverse backwards so we can remove nodes at the same time
				 * without effecting the traversal.
				 * 
				 * TODO: Consider taking into account original contentScore
				 * here.
				 */
				for (var i = curTagsLength - 1; i >= 0; i--) {
					var weight = readability.getClassWeight(tagsList[i]);

					dbg("Cleaning Conditionally "
							+ tagsList[i]
							+ " ("
							+ tagsList[i].className
							+ ":"
							+ tagsList[i].id
							+ ")"
							+ ((typeof tagsList[i].readability != 'undefined')
									? (" with score " + tagsList[i].readability.contentScore)
									: ''));

					if (weight < 0) {
						tagsList[i].parentNode.removeChild(tagsList[i]);
					} else if (readability.getCharCount(tagsList[i], ',') < 10) {
						/**
						 * If there are not very many commas, and the number of
						 * non-paragraph elements is more than paragraphs or
						 * other ominous signs, remove the element.
						 */

						var p = tagsList[i].getElementsByTagName("p").length;
						var img = tagsList[i].getElementsByTagName("img").length;
						var li = tagsList[i].getElementsByTagName("li").length
								- 100;
						var input = tagsList[i].getElementsByTagName("input").length;

						var embedCount = 0;
						var embeds = tagsList[i].getElementsByTagName("embed");
						for (var ei = 0, il = embeds.length; ei < il; ei++) {
							if (embeds[ei].src
									.search(readability.regexps.videoRe) == -1) {
								embedCount++;
							}
						}

						var linkDensity = readability
								.getLinkDensity(tagsList[i]);
						var contentLength = readability
								.getInnerText(tagsList[i]).length;
						var toRemove = false;

						if (img > p) {
							toRemove = true;
						} else if (li > p && tag != "ul" && tag != "ol") {
							toRemove = true;
						} else if (input > Math.floor(p / 3)) {
							toRemove = true;
						} else if (contentLength < 25 && (img == 0 || img > 2)) {
							toRemove = true;
						} else if (weight < 25 && linkDensity > .2) {
							toRemove = true;
						} else if (weight >= 25 && linkDensity > .5) {
							toRemove = true;
						} else if ((embedCount == 1 && contentLength < 75)
								|| embedCount > 1) {
							toRemove = true;
						}

						if (toRemove) {
							tagsList[i].parentNode.removeChild(tagsList[i]);
						}
					}
				}
			},

			/**
			 * Clean out spurious headers from an Element. Checks things like
			 * classnames and link density.
			 * 
			 * @param Element
			 * @return void
			 */
			cleanHeaders : function(e) {
				for (var headerIndex = 1; headerIndex < 7; headerIndex++) {
					var headers = e.getElementsByTagName('h' + headerIndex);
					for (var i = headers.length - 1; i >= 0; i--) {
						if (readability.getClassWeight(headers[i]) < 0
								|| readability.getLinkDensity(headers[i]) > 0.33) {
							headers[i].parentNode.removeChild(headers[i]);
						}
					}
				}
			},

			htmlspecialchars : function(s) {
				if (typeof(s) == "string") {
					s = s.replace(/&/g, "&amp;");
					s = s.replace(/"/g, "&quot;");
					s = s.replace(/'/g, "&#039;");
					s = s.replace(/</g, "&lt;");
					s = s.replace(/>/g, "&gt;");
				}

				return s;
			}

		};
		readability.init(document, document.body.cloneNode(true));

		readabilityCompleted(readability.bodyNode);
	} catch (e) {

	}

}

start();
